/**
 * FlightListGenerator.java
 * Dec 28, 2009
 */
package com.dlplay.flightinfo.presentation;

import java.util.List;

import org.w3c.dom.Document;
import org.w3c.dom.Element;

import com.dlplay.flightinfo.data.Airport;

/**
 * @author zhao yu
 *
 */
public class XMLAirportListGenerator implements XMLGenerator {

	private List<Airport> data;
	
	/**
	 * @param data
	 */
	public XMLAirportListGenerator(List<Airport> data) {
		super();
		this.data = data;
	}
	/* (non-Javadoc)
	 * @see com.dlplay.flightinfo.server.XMLGenerator#generate(org.w3c.dom.Document)
	 */
	@Override
	public void generate(Document document) {
		Element r = document.createElement("FlightList");
		document.appendChild(r);
		for (Airport item : data) {
			Element eltItem = document.createElement("Airport");
			Element eltNum = document.createElement("Name");
			eltNum.appendChild(document.createTextNode(item.getName()));
			eltItem.appendChild(eltNum);
			r.appendChild(eltItem);
		}
		document.normalizeDocument();

	}

}
